FROM docker-mirror.isrc.ac.cn/docker.io/debian:bullseye
MAINTAINER Andrey Volk <andrey@signalwire.com>

ARG PROXY_IP="10.135.18.243"

ENV http_proxy http://${PROXY_IP}:7890
ENV https_proxy http://${PROXY_IP}:7890
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install apt-transport-https ca-certificates

ENV http_proxy ""
ENV https_proxy ""

COPY sources.list /etc/apt/sources.list
COPY gdbserver.sh /root/gdbserver.sh

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install git

RUN git config --global http.proxy http://${PROXY_IP}:7890 \
    && git config --global https.proxy http://${PROXY_IP}:7890

RUN git clone -b v1.10.9 https://github.com/signalwire/freeswitch /usr/src/freeswitch
RUN git clone https://github.com/signalwire/libks /usr/src/libs/libks
RUN git clone https://github.com/freeswitch/sofia-sip /usr/src/libs/sofia-sip
RUN git clone https://github.com/freeswitch/spandsp /usr/src/libs/spandsp
RUN git clone https://github.com/signalwire/signalwire-c /usr/src/libs/signalwire-c

#安装拓展工具
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install \
    net-tools wget curl vim tcpdump tshark postgresql-client

RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install \
    # build
    build-essential cmake automake autoconf 'libtool-bin|libtool' pkg-config \
    # general
    libssl-dev zlib1g-dev libdb-dev unixodbc unixodbc-dev libncurses5-dev libexpat1-dev libgdbm-dev bison erlang-dev libtpl-dev libtiff5-dev uuid-dev \
    # core
    libpcre3-dev libedit-dev libsqlite3-dev libcurl4-openssl-dev nasm \
    # core codecs
    libogg-dev libspeex-dev libspeexdsp-dev \
    # mod_enum
    libldns-dev \
    # mod_python3
    python3-dev \
    # mod_av
    libavformat-dev libswscale-dev libavresample-dev \
    # mod_lua
    liblua5.2-dev \
    # mod_opus
    libopus-dev \
    # mod_pgsql
    libpq-dev \
    # mod_sndfile
    libsndfile1-dev libflac-dev libogg-dev libvorbis-dev \
    # mod_shout
    libshout3-dev libmpg123-dev libmp3lame-dev \
    #Postgres native support was added in FreeSWITCH 1.2.5.
    libpq-dev \
    #gdbserver
    openssh-server gdb gdbserver libwebsockets-dev valgrind

RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && yes root | passwd root

RUN cd /usr/src/libs/libks \
    #You need to either install libks or disable mod_verto in modules.conf
    && git checkout v1.8.3 \
    && cmake . -DCMAKE_INSTALL_PREFIX=/usr -DWITH_LIBBACKTRACE=1 && make install
RUN cd /usr/src/libs/sofia-sip && ./bootstrap.sh && ./configure CFLAGS="-g -ggdb" --with-pic --with-glib=no --without-doxygen --disable-stun --prefix=/usr && make -j`nproc --all` && make install
RUN cd /usr/src/libs/spandsp \
     #FreeSwitch 1.10.9 编译spandsp，V18_MODE_5BIT_4545错误
    && git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4 \
    && ./bootstrap.sh && ./configure CFLAGS="-g -ggdb" --with-pic --prefix=/usr && make -j`nproc --all` && make install
RUN cd /usr/src/libs/signalwire-c \
    #You need to either install signalwire-client-c or disable mod_signalwire in modules.conf
    && git checkout v1.3.3 \
    && PKG_CONFIG_PATH=/usr/lib/pkgconfig cmake . -DCMAKE_INSTALL_PREFIX=/usr && make install

# Enable modules
RUN sed -i 's|#formats/mod_shout|formats/mod_shout|' /usr/src/freeswitch/build/modules.conf.in

RUN cd /usr/src/freeswitch \
#    && ./bootstrap.sh -j \
#    && ./configure \
#       --enable-core-pqsql-support \
    && ./devel-bootstrap.sh --enable-core-pqsql-support \
    && make -j`nproc` && make install

#安装声音文件
RUN cd /usr/src/freeswitch \
    #安装声音文件
    && make moh-install \
    && make sounds-install \
    #安装16kHz声音文件 CD音质的声音文件
    && make cd-moh-install \
    && make cd-sounds-install \
    #mod_portaudio 模块支持你本地的音频设备 可以类似zoiper
    && make mod_portaudio \
    && make mod_portaudio-install

#安装mod_odbc_cdr
RUN cd /usr/src/freeswitch/src/mod/event_handlers/mod_odbc_cdr && make -j`nproc` && make install

RUN ln -sf /usr/local/freeswitch/bin/freeswitch /usr/bin/ \
    && ln -sf /usr/local/freeswitch/bin/fs_cli /usr/bin/

# Cleanup the image
RUN apt-get clean
RUN git config --global --unset http.proxy \
    && git config --global --unset https.proxy

# Uncomment to cleanup even more
#RUN rm -rf /usr/src/*
